Conversation
|
@ndossche I created to deeper test script comparing different streams and behavior (see #23905 (comment)). |
A failed seek reset the internal position to 0 but reported -1 as the stream position, so ftell() returned false and a following SEEK_CUR tripped an assertion. Leave the position unchanged instead, like plain files. php://temp was affected too while its data is held in memory, as it forwards seeks to an inner php://memory stream. Once spilled to a temporary file it already behaved correctly. Its seek no longer reports -1 either when it has no inner stream.
A failed seek discarded the read buffer although the stream did not move. A buffered stream has usually read ahead, so a following read or write continued from where the stream had read ahead to, while ftell() still reported the old position. Return early instead, keeping the position, the read buffer and the filter state.
A failed seek clamped the internal position to 0 or the blob size but reported -1 as the stream position, so ftell() returned false and a following SEEK_CUR tripped an assertion. Leave both positions unchanged instead, and reject a negative SEEK_SET offset explicitly rather than relying on the size_t cast.
A failed seek clamped the internal position to 0 or the blob size but reported -1 as the stream position, so ftell() returned false and a following SEEK_CUR tripped an assertion. Leave both positions unchanged instead, and reject a negative SEEK_SET offset explicitly rather than relying on the size_t cast.
0b8091a to
bc78826
Compare
|
@ndossche I reworked the branch and updated it to latest PHP-8.6. What has been changed since last?
New commit: $fp = fopen($file, 'r+'); // "hello world"
fread($fp, 5); // "hello"
fseek($fp, -12, SEEK_END); // -1, ftell() is still 5
fread($fp, 5); // before: "", now: " worl"A failed seek now returns early and keeps the position, the read buffer and the filter state. The new test
Not addressed / possible follow-ups
|
fixes #23905
This is targeting 8.6 even if this bug exists on 8.4 as well but #21433 conflicts and targets 8.6.
Please tell me if I should target PHP-8.4 instead.